Database lockng mechanism

ABSTRACT

A method for preventing race conditions in a database comprises: setting a first numerical entry and a second numerical entry in a database; receiving a first online transaction; responsive to determining a lock of the database is in progress due to a second received online transaction, suspending the first online transaction; removing the lock after the second received online transaction is completed; responsive to determining that the first entry is greater than zero, decrementing the first entry by an amount indicated in the first online transaction; responsive to determining the second entry is greater than zero, decrementing the second entry; processing the first transaction; and generating an online transaction record for the first transaction and storing the generated record in an online transaction database.

CROSS REFERENCE TO RELATED APPLICATIONS

This application is a continuation-in-part of U.S. patent applicationSer. No. 17/489,062 filed Sep. 29, 2021.

FIELD

The subject matter disclosed herein generally relates to the technicalfield of databases and more specifically, to locking databases toprevent race conditions.

BACKGROUND

A race condition occurs when a device or system attempts to perform twoor more operations simultaneously, but the operations must be done insequence to be handled correctly. In the field of databases, a racecondition can occur when two separate programs or other entitiesattempts to write simultaneously to a same single entry in the databaseinstead of sequentially. This can cause data corruption, which isundesirable in a database.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

Some embodiments are illustrated by way of example and not limitation inthe views of the accompanying drawing:

FIG. 1 is a block diagram illustrating a networked system, according tosome example embodiments.

FIG. 2 is a block diagram showing architectural aspects of a publicationsystem, according to some example embodiments.

FIG. 3 is a block diagram illustrating a representative softwarearchitecture, which may be used in conjunction with various hardwarearchitectures herein described

FIG. 4 is a block diagram illustrating components of a machine,according to some example embodiments, able to read instructions from amachine-readable medium (e.g., a machine-readable storage medium) andperform any one or more of the methodologies discussed herein.

FIG. 5 is a block diagram showing aspects of an online method forconducting a transaction between a merchant site and an electronic userdevice using a payment processor, according to some example embodiments.

FIG. 6 is a block diagram showing aspects of an inventory system,according to some example embodiments.

FIG. 7 illustrates a method of preventing race conditions in aninventory database, according to some example embodiments.

DETAILED DESCRIPTION

“Carrier Signal”, in this context, refers to any intangible medium thatis capable of storing, encoding, or carrying instructions for executionby a machine, and includes digital or analog communication signals orother intangible media to facilitate communication of such instructions.Instructions may be transmitted or received over a network using atransmission medium via a network interface device and using any one ofa number of well-known transfer protocols.

“Client Device” or “Electronic Device”, in this context, refers to anymachine that interfaces to a communications network to obtain resourcesfrom one or more server systems or other client devices. A client devicemay be, but is not limited to, a mobile phone, desktop computer, laptop,portable digital assistant (PDA), smart phone, tablet, ultra-book,netbook, laptop, multi-processor system, microprocessor-based orprogrammable consumer electronic system, game console, set-top box, orany other communication device that a user may use to access a network.

“Customer's Electronic Device” or “Electronic User Device”, in thiscontext, refers to a client device that a customer uses to interact witha merchant. Examples of this device include a desktop computer, a laptopcomputer, a mobile device (e.g., smartphone, tablet), and a gameconsole. The customer's electronic device may interact with the merchantvia a browser application that executes on the customer's electronicdevice or via a native app installed onto the customer's electronicdevice. The client-side application executes on the customer'selectronic device.

“Communications Network”, in this context, refers to one or moreportions of a network that may be an ad hoc network, an intranet, anextranet, a virtual private network (VPN), a local area network (LAN), awireless LAN (WLAN), a wide area network (WAN), a wireless WAN (WWAN), ametropolitan area network (MAN), the Internet, a portion of theInternet, a portion of the Public Switched Telephone Network (PSTN), aplain old telephone service (POTS) network, a cellular telephonenetwork, a wireless network, a Wi-Fi® network, another type of network,or a combination of two or more such networks. For example, a network ora portion of a network may include a wireless or cellular network, andthe coupling may be a Code Division Multiple Access (CDMA) connection, aGlobal System for Mobile communications (GSM) connection, or anothertype of cellular or wireless coupling. In this example, the coupling mayimplement any of a variety of types of data transfer technology, such asSingle Carrier Radio Transmission Technology (1×RTT), Evolution-DataOptimized (EVDO) technology, General Packet Radio Service (GPRS)technology, Enhanced Data rates for GSM Evolution (EDGE) technology,third Generation Partnership Project (3GPP) including 3G, fourthgeneration wireless (4G) networks, Universal Mobile TelecommunicationsSystem (UMTS), High-Speed Packet Access (HSPA), WorldwideInteroperability for Microwave Access (WiMAX), Long-Term Evolution (LTE)standard, others defined by various standard-setting organizations,other long-range protocols, or other data transfer technology.

“Component”, in this context, refers to a device, physical entity, orlogic having boundaries defined by function or subroutine calls, branchpoints, application programming interfaces (APIs), or other technologiesthat provide for the partitioning or modularization of particularprocessing or control functions. Components may be combined via theirinterfaces with other components to carry out a machine process. Acomponent may be a packaged functional hardware unit designed for usewith other components and a part of a program that usually performs aparticular function of related functions. Components may constituteeither software components (e.g., code embodied on a machine-readablemedium) or hardware components.

A “hardware component” is a tangible unit capable of performing certainoperations and may be configured or arranged in a certain physicalmanner. In various example embodiments, one or more computer systems(e.g., a standalone computer system, a client computer system, or aserver computer system) or one or more hardware components of a computersystem (e.g., a processor or a group of processors) may be configured bysoftware (e.g., an application or application portion) as a hardwarecomponent that operates to perform certain operations as describedherein. A hardware component may also be implemented mechanically,electronically, or any suitable combination thereof. For example, ahardware component may include dedicated circuitry or logic that ispermanently configured to perform certain operations. A hardwarecomponent may be a special-purpose processor, such as afield-programmable gate array (FPGA) or an application-specificintegrated circuit (ASIC). A hardware component may also includeprogrammable logic or circuitry that is temporarily configured bysoftware to perform certain operations. For example, a hardwarecomponent may include software executed by a general-purpose processoror other programmable processor. Once configured by such software,hardware components become specific machines (or specific components ofa machine) uniquely tailored to perform the configured functions and areno longer general-purpose processors.

It will be appreciated that the decision to implement a hardwarecomponent mechanically, in dedicated and permanently configuredcircuitry, or in temporarily configured circuitry (e.g., configured bysoftware) may be driven by cost and time considerations. Accordingly,the phrase “hardware component” (or “hardware-implemented component”)should be understood to encompass a tangible entity, be that an entitythat is physically constructed, permanently configured (e.g.,hardwired), or temporarily configured (e.g., programmed) to operate in acertain manner or to perform certain operations described herein.Considering embodiments in which hardware components are temporarilyconfigured (e.g., programmed), each of the hardware components need notbe configured or instantiated at any one instant in time. For example,where a hardware component comprises a general-purpose processorconfigured by software to become a special-purpose processor, thegeneral-purpose processor may be configured as respectively differentspecial-purpose processors (e.g., comprising different hardwarecomponents) at different times. Software accordingly configures aparticular processor or processors, for example, to constitute aparticular hardware component at one instant of time and to constitute adifferent hardware component at a different instant of time. Hardwarecomponents can provide information to, and receive information from,other hardware components. Accordingly, the described hardwarecomponents may be regarded as being communicatively coupled. Wheremultiple hardware components exist contemporaneously, communications maybe achieved through signal transmission (e.g., over appropriate circuitsand buses) between or among two or more of the hardware components. Inembodiments in which multiple hardware components are configured orinstantiated at different times, communications between such hardwarecomponents may be achieved, for example, through the storage andretrieval of information in memory structures to which the multiplehardware components have access. For example, one hardware component mayperform an operation and store the output of that operation in a memorydevice to which it is communicatively coupled. A further hardwarecomponent may then, at a later time, access the memory device toretrieve and process the stored output. Hardware components may alsoinitiate communications with input or output devices, and can operate ona resource (e.g., a collection of information).

The various operations of example methods described herein may beperformed, at least partially, by one or more processors that aretemporarily configured (e.g., by software) or permanently configured toperform the relevant operations. Whether temporarily or permanentlyconfigured, such processors may constitute processor-implementedcomponents that operate to perform one or more operations or functionsdescribed herein. As used herein, “processor-implemented component”refers to a hardware component implemented using one or more processors.Similarly, the methods described herein may be at least partiallyprocessor-implemented, with a particular processor or processors beingan example of hardware. For example, at least some of the operations ofa method may be performed by one or more processors orprocessor-implemented components. Moreover, the one or more processorsmay also operate to support performance of the relevant operations in a“cloud computing” environment or as a “software as a service” (SaaS).For example, at least some of the operations may be performed by a groupof computers (as examples of machines including processors), with theseoperations being accessible via a network (e.g., the Internet) and viaone or more appropriate interfaces (e.g., an API). The performance ofcertain of the operations may be distributed among the processors, notonly residing within a single machine, but deployed across a number ofmachines. In some example embodiments, the processors orprocessor-implemented components may be located in a single geographiclocation (e.g., within a home environment, an office environment, or aserver farm). In other example embodiments, the processors orprocessor-implemented components may be distributed across a number ofgeographic locations.

“Machine-Readable Medium” in this context refers to a component, device,or other tangible medium able to store instructions and data temporarilyor permanently and may include, but not be limited to, random-accessmemory (RAM), read-only memory (ROM), buffer memory, flash memory,optical media, magnetic media, cache memory, other types of storage(e.g., erasable programmable read-only memory (EPROM)), and/or anysuitable combination thereof. The term “machine-readable medium” shouldbe taken to include a single medium or multiple media (e.g., acentralized or distributed database, or associated caches and servers)able to store instructions. The term “machine-readable medium” shallalso be taken to include any medium, or combination of multiple media,that is capable of storing instructions (e.g., code) for execution by amachine, such that the instructions, when executed by one or moreprocessors of the machine, cause the machine to perform any one or moreof the methodologies described herein. Accordingly, a “machine-readablemedium” refers to a single storage apparatus or device, as well as“cloud-based” storage systems or storage networks that include multiplestorage apparatus or devices. The term “machine-readable medium”excludes signals per se.

“Processor”, in one context, refers to any circuit or virtual circuit (aphysical circuit emulated by logic executing on an actual processor)that manipulates data values according to control signals (e.g.,“commands,” “op codes,” “machine code,” etc.) and which producescorresponding output signals that are applied to operate a machine. Aprocessor may, for example, be a central processing unit (CPU), areduced instruction set computing (RISC) processor, a complexinstruction set computing (CISC) processor, a graphics processing unit(GPU), a digital signal processor (DSP), an ASIC, a radio-frequencyintegrated circuit (RFIC), or any combination thereof. A processor mayfurther be a multi-core processor having two or more independentprocessors (sometimes referred to as “cores”) that may executeinstructions contemporaneously.

In another context, a “Processor” (e.g., processor 514 in FIG. 5 ) is acompany (often a third party) appointed to handle payment card (e.g.,credit card, debit card) transactions. They have connections to variouscard networks and supply authorization and settlement services tomerchants or payment service providers. In aspects, they can also movethe money from an issuing bank to a merchant or acquiring bank.

“Card Network” (or “Card Association”), in this context, refers tofinancial payment networks such as Visa®, MasterCard®, AmericanExpress®, Diners Club®, JCB®, and China Union-Pay®.

“Acquiring Bank” or “Acquirer”, in this context, refers to a bank orfinancial institution that accepts credit and/or debit card paymentsfrom affiliated card networks for products or services on behalf of amerchant or payment service provider.

“Card Issuing Bank” or “Issuing Bank”, in this context, refers to a bankthat offers card network or association-branded payment cards directlyto consumers. An issuing bank assumes primary liability for theconsumer's capacity to pay off debts they incur with their card.

“Payment Information” includes information required to complete atransaction, and the specific type of information provided may vary bypayment type. Some payment information will be sensitive (e.g., the cardvalidation code), while other information might not be (e.g., zip code).For example, when a payment is made via a credit card or debit card, thepayment information includes a primary account number (PAN) or creditcard number, card validation code, and expiration month and year. Inanother payment example, made using an Automated Clearinghouse (ACH)transaction for example, the payment information includes a bank routingnumber and an account number within that bank.

“Sensitive information” may not necessarily be related to paymentinformation and may include other confidential personal information,such as medical (e.g., HIPAA) information, for example. The ambit of theterm “Payment Information” includes “Sensitive Information” within itsscope. In some examples, sensitive payment information may include“regulated payment information,” which may change over time. Forexample, currently a merchant cannot collect more than the first six (6)or the last four (4) numbers of a customer's PAN without generallyneeding to comply with Payment Card Industry (PCI) regulations. But cardnumber lengths may change, and when they do, the “6 and 4” rules willlikely change with them. These potential future changes are incorporatedwithin the ambit of “regulated payment information,” which is, in turn,included within the ambit of the term “payment information” as definedherein.

“Merchant”, in this context, refers to an entity that is associated withselling or licensing products and/or services over electronic systemssuch as the Internet and other computer networks. The merchant may bethe direct seller/licensor, or the merchant may be an agent for a directseller/licensor. For example, entities such as Amazon® sometimes act asthe direct seller/licensor, and sometimes act as an agent for a directseller/licensor.

“Merchant Site”, in this context, refers to an e-commerce site or portal(e.g., website, or mobile app) of the merchant. In some figures, themerchant (e.g., a merchant 502 of FIG. 5 ) and merchant servers (e.g.,merchant servers 506 of FIG. 5 ) are associated with the merchant site.The merchant site is associated with a client-side application and aserver-side application. In one example embodiment, the merchant siteincludes the merchant servers 506 of FIG. 5 , and the server-sideapplication executes on the merchant servers 506.

“Payment Processor”, in this context, (e.g., a payment processor 510 inFIG. 5 ) refers to an entity or a plurality of entities that facilitatea transaction, for example between a merchant and a customer'selectronic device. With reference to a high-level descriptionillustrated in FIG. 5 , in some examples described more fully below, thepayment processor includes selected functionality of both the paymentprocessor 510 and processor 514/card networks 516. For example, thepayment processor 510 creates tokens and maintains and verifiespublishable (non-secret) keys and secret keys. In the illustratedexample, the processor 514/card networks 516 are involved in authorizingor validating payment information. In one example embodiment, thepayment processor 510 and the processor 514/card networks 516 functiontogether to authorize and validate payment information, issue a token,and settle any charges that are made. Accordingly, in this embodiment,“payment processor” refers to the functionality of the payment processor510 and the functionality of the processor 514/card networks 516. Inanother example embodiment, wherein step (3) in the high-leveldescription is not performed, and the payment processor 510 performs itsown verification before issuing a token, the processor 514/card networks516 are still used for settling any charges that are made, as describedin step (7). Accordingly, in this embodiment, “payment processor” mayrefer only to the functionality of the payment processor 510 withrespect to issuing tokens. Further, in the example arrangement shown,the payment processor 510, the processor 514, and the card networks 516are shown as separate entities. In some examples, their respectivefunctions may be performed by two entities, or even just one entity,with the entities themselves being configured accordingly.

“Native Application” or “native app”, in this context, refers to an appcommonly used with a mobile device, such as a smartphone or tablet. Whenused with a mobile device, the native app is installed directly onto themobile device. Mobile device users typically obtain these apps throughan online store or marketplace, such as an app store (e.g., Apple's AppStore, Google Play store). More generically, a native application isdesigned to run in the computer environment (machine language andoperating system) that it is being run in. It can be referred to as a“locally installed application.” A native application differs from aninterpreted application, such as a Java applet, which requiresinterpreter software. A native application also differs from an emulatedapplication that is written for a different platform and converted inreal time to run, and a web application that is run within the browser.

A portion of the disclosure of this patent document contains materialthat is subject to copyright protection. The copyright owner has noobjection to the facsimile reproduction by anyone of the patent documentor the patent disclosure, as it appears in the Patent and TrademarkOffice patent files or records, but otherwise reserves all copyrightrights whatsoever. The following notice applies to the software and dataas described below and in the drawings that form a part of thisdocument: Copyright 2011-2021, Stripe, Inc., All Rights Reserved.

The description that follows includes systems, methods, techniques,instruction sequences, and computing machine program products thatembody illustrative embodiments of the disclosure. In the followingdescription, for the purposes of explanation, numerous specific detailsare set forth in order to provide an understanding of variousembodiments of the inventive subject matter. It will be evident,however, to those skilled in the art, that embodiments of the inventivesubject matter may be practiced without these specific details. Ingeneral, well-known instruction instances, protocols, structures, andtechniques are not necessarily shown in detail. In this specification,the terms “user”, “cardholder”, and “consumer” are used interchangeablyunless the context indicates otherwise.

With reference to FIG. 1 , an example embodiment of a high-level SaaSnetwork architecture 100 is shown. A networked system 116 providesserver-side functionality via a network 110 (e.g., the Internet or aWAN) to a client device 108. A web client 102 and a programmatic client,in the example form of a client application 104, are hosted and executeon the client device 108. The networked system 116 includes anapplication server 122, which in turn hosts a publication system 106(such as the publication system hosted at https://stripe.com by Stripe,Inc. of San Francisco, Calif. (herein “Stripe”) as an example of apayment processor 510) that provides a number of functions and servicesto the client application 104 that accesses the networked system 116.The client application 104 also provides a number of interfacesdescribed herein, which present output of push payment decision routingto a user of the client device 108.

The client device 108 enables a user to access and interact with thenetworked system 116 and, ultimately, the publication system 106. Forinstance, the user provides input (e.g., touch screen input oralphanumeric input) to the client device 108, and the input iscommunicated to the networked system 116 via the network 110. In thisinstance, the networked system 116, in response to receiving the inputfrom the user, communicates information back to the client device 108via the network 110 to be presented to the user.

An API server 118 and a web server 120 are coupled, and provideprogrammatic and web interfaces respectively, to the application server122. The application server 122 hosts the publication system 106, whichincludes components or applications described further below. Theapplication server 122 is, in turn, shown to be coupled to a databaseserver 124 that facilitates access to information storage repositories(e.g., a database 126). In an example embodiment, the database 126includes storage devices that store information accessed and generatedby the publication system 106.

Additionally, a third-party application 114, executing on one or morethird-party servers 112, is shown as having programmatic access to thenetworked system 116 via the programmatic interface provided by the APIserver 118. For example, the third-party application 114, usinginformation retrieved from the networked system 116, may support one ormore features or functions on a website hosted by a third party.

Turning now specifically to the applications hosted by the client device108, the web client 102 may access the various systems (e.g., thepublication system 106) via the web interface supported by the webserver 120. Similarly, the client application 104 (e.g., an “app” suchas a payment processor app) accesses the various services and functionsprovided by the publication system 106 via the programmatic interfaceprovided by the API server 118. The client application 104 may be, forexample, an “app” executing on the client device 108, such as an iOS orAndroid OS application to enable a user to access and input data on thenetworked system 116 in an offline manner and to perform batch-modecommunications between the programmatic client application 104 and thenetworked system 116.

Further, while the SaaS network architecture 100 shown in FIG. 1 employsa client-server architecture, the present inventive subject matter is,of course, not limited to such an architecture, and could equally wellfind application in a distributed, or peer-to-peer, architecture system,for example. The publication system 106 could also be implemented as astandalone software program, which does not necessarily have networkingcapabilities.

FIG. 2 is a block diagram showing architectural details of a publicationsystem 106, according to some example embodiments. Specifically, thepublication system 106 is shown to include an interface component 202 bywhich the publication system 106 communicates (e.g., over a network 110)with other systems within the SaaS network architecture 100.

The interface component 202 is communicatively coupled to a paymentprocessor component 300 that operates to provide push payment decisionrouting for a payment processor 510 in accordance with the methodsdescribed herein with reference to the accompanying drawings.

FIG. 3 is a block diagram illustrating an example software architecture306, which may be used in conjunction with various hardwarearchitectures herein described. FIG. 3 is a non-limiting example of asoftware architecture 306, and it will be appreciated that many otherarchitectures may be implemented to facilitate the functionalitydescribed herein. The software architecture 306 may execute on hardwaresuch as a machine 400 of FIG. 4 that includes, among other things,processors 404, memory/storage 406, and input/output (I/O) components418. A representative hardware layer 350 is illustrated and canrepresent, for example, the machine 400 of FIG. 4 . The representativehardware layer 350 includes a processor 352 having associated executableinstructions 304. The executable instructions 304 represent theexecutable instructions of the software architecture 306, includingimplementation of the methods, components, and so forth describedherein. The hardware layer 350 also includes memory and/or storagemodules as memory/storage 354, which also have the executableinstructions 304. The hardware layer 350 may also comprise otherhardware 356.

In the example architecture of FIG. 3 , the software architecture 306may be conceptualized as a stack of layers where each layer providesparticular functionality. For example, the software architecture 306 mayinclude layers such as an operating system 302, libraries 322,frameworks/middleware 318, applications 316, and a presentation layer314. Operationally, the applications 316 and/or other components withinthe layers may invoke API calls 308 through the software stack andreceive a response as messages 312 in response to the API calls 308. Thelayers illustrated are representative in nature, and not all softwarearchitectures have all layers. For example, some mobile orspecial-purpose operating systems may not provide aframeworks/middleware 318, while others may provide such a layer. Othersoftware architectures may include additional or different layers.

The operating system 302 may manage hardware resources and providecommon services. The operating system 302 may include, for example, akernel 320, services 324, and drivers 326. The kernel 320 may act as anabstraction layer between the hardware and the other software layers.For example, the kernel 320 may be responsible for memory management,processor management (e.g., scheduling), component management,networking, security settings, and so on. The services 324 may provideother common services for the other software layers. The drivers 326 areresponsible for controlling or interfacing with the underlying hardware.For instance, the drivers 326 include display drivers, camera drivers,Bluetooth® drivers, flash memory drivers, serial communication drivers(e.g., Universal Serial Bus (USB) drivers), Wi-Fi® drivers, audiodrivers, power management drivers, and so forth depending on thehardware configuration.

The libraries 322 provide a common infrastructure that is used by theapplications 316 and/or other components and/or layers. The libraries322 provide functionality that allows other software components toperform tasks in an easier fashion than by interfacing directly with theunderlying operating system 302 functionality (e.g., kernel 320,services 324, and/or drivers 326). The libraries 322 may include systemlibraries 344 (e.g., C standard library) that may provide functions suchas memory allocation functions, string manipulation functions,mathematical functions, and the like. In addition, the libraries 322 mayinclude API libraries 346 such as media libraries (e.g., libraries tosupport presentation and manipulation of various media formats such asMPEG4, H.264, MP3, AAC, AMR, JPG, and PNG), graphics libraries (e.g., anOpenGL framework that may be used to render 2D and 3D graphic content ona display), database libraries (e.g., SQLite that may provide variousrelational database functions), web libraries (e.g., WebKit that mayprovide web browsing functionality), and the like. The libraries 322 mayalso include a wide variety of other libraries 348 to provide many otherAPIs to the applications 316 and other software components/modules.

The frameworks/middleware 318 provide a higher-level commoninfrastructure that may be used by the applications 316 and/or othersoftware components/modules. For example, the frameworks/middleware 318may provide various graphic user interface (GUI) functions 342,high-level resource management, high-level location services, and soforth. The frameworks/middleware 318 may provide a broad spectrum ofother APIs that may be utilized by the applications 316 and/or othersoftware components/modules, some of which may be specific to aparticular operating system 302 or platform.

The applications 316 include built in applications 338 and/orthird-party applications 340. Examples of representative built inapplications 338 may include, but are not limited to, a contactsapplication, a browser application, a book reader application, alocation application, a media application, a messaging application,and/or a game application. The third-party applications 340 may includeany application developed using the ANDROID™ or IOS™ softwaredevelopment kit (SDK) by an entity other than the vendor of theparticular platform and may be mobile software running on a mobileoperating system such as IOS™, ANDROID™, WINDOWS® Phone, or other mobileoperating systems. The third-party applications 340 may invoke the APIcalls 308 provided by the mobile operating system (such as the operatingsystem 302) to facilitate functionality described herein.

The applications 316 may use built-in operating system functions (e.g.,kernel 320, services 324, and/or drivers 326), libraries 322, andframeworks/middleware 318 to create user interfaces to interact withusers of the system. Alternatively, or additionally, in some systems,interactions with a user may occur through a presentation layer, such asthe presentation layer 314. In these systems, the application/component“logic” can be separated from the aspects of the application/componentthat interact with a user.

Some software architectures use virtual machines. In the example of FIG.3 , this is illustrated by a virtual machine 310. The virtual machine310 creates a software environment where applications/components canexecute as if they were executing on a hardware machine (such as themachine 400 of FIG. 4 , for example). The virtual machine 310 is hostedby a host operating system (e.g., the operating system 302 in FIG. 3 )and typically, although not always, has a virtual machine monitor 358,which manages the operation of the virtual machine 310 as well as theinterface with the host operating system (e.g., the operating system302). A software architecture executes within the virtual machine 310such as an operating system (OS) 336, libraries 334, frameworks 332,applications 330, and/or a presentation layer 328. These layers ofsoftware architecture executing within the virtual machine 310 can bethe same as corresponding layers previously described or may bedifferent.

FIG. 4 is a block diagram illustrating components of a machine 400,according to some example embodiments, able to read instructions 304from a machine-readable medium (e.g., a machine-readable storage medium)and perform any one or more of the methodologies discussed herein.Specifically, FIG. 4 shows a diagrammatic representation of the machine400 in the example form of a computer system, within which instructions410 (e.g., software, a program, an application, an applet, an app, orother executable code) for causing the machine 400 to perform any one ormore of the methodologies discussed herein may be executed. As such, theinstructions 410 may be used to implement modules or componentsdescribed herein. The instructions 410 transform the general,non-programmed machine 400 into a particular machine 400 programmed tocarry out the described and illustrated functions in the mannerdescribed. In alternative embodiments, the machine 400 operates as astandalone device or may be coupled (e.g., networked) to other machines.In a networked deployment, the machine 400 may operate in the capacityof a server machine or a client machine in a server-client networkenvironment, or as a peer machine in a peer-to-peer (or distributed)network environment. The machine 400 may comprise, but not be limitedto, a server computer, a client computer, a personal computer (PC), atablet computer, a laptop computer, a netbook, a set-top box (STB), apersonal digital assistant (PDA), an entertainment media system, acellular telephone, a smart phone, a mobile device, a wearable device(e.g., a smart watch), a smart home device (e.g., a smart appliance),other smart devices, a web appliance, a network router, a networkswitch, a network bridge, or any machine capable of executing theinstructions 410, sequentially or otherwise, that specify actions to betaken by the machine 400. Further, while only a single machine 400 isillustrated, the term “machine” shall also be taken to include acollection of machines that individually or jointly execute theinstructions 410 to perform any one or more of the methodologiesdiscussed herein.

The machine 400 may include processors 404 (including processor 408 andprocessor 412), memory/storage 406, and I/O components 418, which may beconfigured to communicate with each other such as via a bus 402. Thememory/storage 406 may include a memory 414, such as a main memory, orother memory storage, and a storage unit 416, both accessible to theprocessors 404 such as via the bus 402. The storage unit 416 and memory414 store the instructions 410 embodying any one or more of themethodologies or functions described herein. The instructions 410 mayalso reside, completely or partially, within the memory 414, within thestorage unit 416, within at least one of the processors 404 (e.g.,within the processor's cache memory), or any suitable combinationthereof, during execution thereof by the machine 400. Accordingly, thememory 414, the storage unit 416, and the memory of the processors 404are examples of machine-readable media.

The I/O components 418 may include a wide variety of components toreceive input, provide output, produce output, transmit information,exchange information, capture measurements, and so on. The specific I/Ocomponents 418 that are included in a particular machine 400 will dependon the type of machine. For example, portable machines such as mobilephones will likely include a touch input device or other such inputmechanisms, while a headless server machine will likely not include sucha touch input device. It will be appreciated that the I/O components 418may include many other components that are not shown in FIG. 4 . The I/Ocomponents 418 are grouped according to functionality merely forsimplifying the following discussion, and the grouping is in no waylimiting. In various example embodiments, the I/O components 418 mayinclude output components 426 and input components 428. The outputcomponents 426 may include visual components (e.g., a display such as aplasma display panel (PDP), a light-emitting diode (LED) display, aliquid crystal display (LCD), a projector, or a cathode ray tube (CRT)),acoustic components (e.g., speakers), haptic components (e.g., avibratory motor, resistance mechanisms), other signal generators, and soforth. The input components 428 may include alphanumeric inputcomponents (e.g., a keyboard, a touch screen configured to receivealphanumeric input, a photo-optical keyboard, or other alphanumericinput components), point-based input components (e.g., a mouse, atouchpad, a trackball, a joystick, a motion sensor, or other pointinginstruments), tactile input components (e.g., a physical button, a touchscreen that provides location and/or force of touches or touch gestures,or other tactile input components), audio input components (e.g., amicrophone), and the like.

In further example embodiments, the I/O components 418 may includebiometric components 430, motion components 436, environment components434, or position components 438, among a wide array of other components.For example, the biometric components 430 may include components todetect expressions (e.g., hand expressions, facial expressions, vocalexpressions, body gestures, or eye tracking), measure biosignals (e.g.,blood pressure, heart rate, body temperature, perspiration, or brainwaves), identify a person (e.g., voice identification, retinalidentification, facial identification, fingerprint identification, orelectroencephalogram-based identification), and the like. The motioncomponents 436 may include acceleration sensor components (e.g.,accelerometer), gravitation sensor components, rotation sensorcomponents (e.g., gyroscope), and so forth. The environment components434 may include, for example, illumination sensor components (e.g.,photometer), temperature sensor components (e.g., one or morethermometers that detect ambient temperature), humidity sensorcomponents, pressure sensor components (e.g., barometer), acousticsensor components (e.g., one or more microphones that detect backgroundnoise), proximity sensor components (e.g., infrared sensors that detectnearby objects), gas sensors (e.g., gas sensors to detect concentrationsof hazardous gases for safety or to measure pollutants in theatmosphere), or other components that may provide indications,measurements, or signals corresponding to a surrounding physicalenvironment. The position components 438 may include location sensorcomponents (e.g., a Global Positioning System (GPS) receiver component),altitude sensor components (e.g., altimeters or barometers that detectair pressure from which altitude may be derived), orientation sensorcomponents (e.g., magnetometers), and the like.

Communication may be implemented using a wide variety of technologies.The I/O components 418 may include communication components 440 operableto couple the machine 400 to a network 432 or devices 420 via a coupling424 and a coupling 422, respectively. For example, the communicationcomponents 440 may include a network interface component or othersuitable device to interface with the network 432. In further examples,the communication components 440 may include wired communicationcomponents, wireless communication components, cellular communicationcomponents, near field communication (NFC) components, Bluetooth®components (e.g., Bluetooth® Low Energy), Wi-Fi® components, and othercommunication components to provide communication via other modalities.The devices 420 may be another machine or any of a wide variety ofperipheral devices (e.g., a peripheral device coupled via a USB).

Moreover, the communication components 440 may detect identifiers orinclude components operable to detect identifiers. For example, thecommunication components 440 may include Radio Frequency Identification(RFID) tag reader components, NFC smart tag detection components,optical reader components (e.g., an optical sensor to detectone-dimensional bar codes such as Universal Product Code (UPC) bar code,multi-dimensional bar codes such as Quick Response (QR) code, Azteccode, Data Matrix, Dataglyph, MaxiCode, PDF417, Ultra Code, UCC RSS-2Dbar code, and other optical codes), or acoustic detection components(e.g., microphones to identify tagged audio signals). In addition, avariety of information may be derived via the communication components440, such as location via Internet Protocol (IP) geo-location, locationvia Wi-Fi® signal triangulation, location via detecting an NFC beaconsignal that may indicate a particular location, and so forth.

In some embodiments, a JavaScript library can be embedded into amerchant 502's checkout form to handle credit card information. When auser attempts to complete a transaction using the checkout form, itsends the credit card information directly from the user's browser tothe payment processor 510's servers. The JavaScript library providesmerchants 502 with a set of technologies that can be easily and quicklyintegrated to securely accept payments online. With the JavaScriptlibrary, merchants 502 retain full control of their customers' paymentflows, but their servers are never exposed to sensitive paymentinformation.

When added to a merchant's payment form, the JavaScript libraryautomatically intercepts the payment form submission, sending paymentinformation directly to the payment processor 510 and converting it to asingle-use token. The single-use token can be safely passed to themerchant's systems and used later to charge customers. Merchants 502have complete control of their customers' payment experience withoutever handling, processing, or storing sensitive payment information.

Viewed generally in one example, and with reference to FIG. 5 , apayment processing flow is now described:

The merchant's customer 504 uses an Internet-enabled browser 512 tovisit the merchant's site. The customer 504 is served a JavaScriptlibrary-enabled payment form 520 using standard web technologies. Thecustomer 504 enters the specified information including their paymentinformation 524 and submits the payment form 520. The billing infoportion of the payment form 520 is for payment via a credit card ordebit card. If payment is to be made via an ACH transaction, the billinginfo portion of the payment form 520 will request a bank routing numberand an account number within that bank, and possibly additionalinformation, such as the bank name and whether the account is a checkingor savings account.

The customer's payment information 524 is sent from the customer'sbrowser 512 to the payment processor 510, never touching the merchantservers 506. In this manner, the client-side application electronicallysends payment information 524 retrieved from the customer's electronicdevice to the payment processor 510. The client-side application doesnot send the payment information 524 to the server-side application.

In one embodiment, the payment processor 510 submits the relevanttransaction to a processor 514 or directly to the card network 516 forauthorization or validation of the payment information 524. The cardnetwork 516 sends the request to the card issuing bank 518, whichauthorizes the transaction. In this embodiment, the payment processor510 and the processor 514/card network 516 function together as apayment processor 510. In another example embodiment, this step isperformed without any communication to the processor 514/card network516. Instead, the payment processor 510 performs its own authorizationor validation of the payment information 524 using heuristic means, suchas by checking the bank identification number (BIN), also referred to asthe issuer identification number (IIN), against a database 126 of known,valid BINs on file with the payment processor 510. (The BIN is a part ofthe bank card number, namely the first six digits.) In yet anotherexample embodiment, this step is not performed at all since theauthorization or validation is not necessary for the next step (4) tosucceed. That is, it is acceptable to create a single-use token in step(4) that represents payment information 524 which has not been validatedin any way.

If authorized, the payment processor 510 will generate and return asecure, single-use token 522 to the customer's browser 512 thatrepresents the customer's payment information 524 but does not leak anysensitive information. In the example embodiment wherein step (3) is notperformed, the payment processor 510 performs this step without waitingto receive authorization from the processor 514 or the card network 516.In this manner, the payment processor 510 creates the token 522 from thepayment information 524 sent by the client-side application, wherein thetoken 522 functions as a proxy for the payment information 524.

The payment form 520 is submitted to the merchant servers 506, includingthe single-use token 522. More specifically, the payment processor 510sends the token 522 to the client-side application, which, in turn,sends the token 522 to the server-side application for use by theserver-side application in conducting the transaction.

The merchant 502 uses the single-use token 522 to submit a chargerequest to the payment processor 510 (or to create a customer object forlater use). In this step, the payment processor 510 submits a request toauthorize the charge to the processor 514 or directly to the cardnetwork 516. This authorization specifies the actual amount to chargethe credit card. If an authorization was already done in step (3) forthe correct amount, this authorization request can be skipped. This maybe a one-time payment for a merchant item, or it may involve registeringthe payment information 524 with the merchant site for subsequent use inmaking a payment for a merchant item (a so-called “card on file”scenario). Using the process described in steps (1) through (6), thepayment information 524 can be used by the server-side application viathe token 522 without the server-side application being exposed to thepayment information 524.

The payment processor 510 settles the charge on behalf of the merchant502 with the processor 514 or directly with the card network 516.

The card network 516 causes the funds to be paid by the card issuingbank 518 to the payment processor 510 or to the payment processor'sacquiring bank 508.

The payment processor 510 causes the settled funds to be sent to themerchant 502 (or to the merchant's bank 526), net of any applicablefees.

The card issuing bank 518 collects the paid funds from the customer 504.

Not all of the steps listed above need happen in real time. Otherexamples, arrangements, and functionality are possible. Applicant'spublished patent application US 2013/0117185 A1 is incorporated byreference in its entirety in this regard. Typically, when the merchant'scustomer 504 submits the payment form 520 in step (1), steps (1) through(6) happen in real time and steps (7) through (10) happen later, usuallyonce per day, as a batch process settling all of the funds for all ofthe payment processor 510's merchants 502. In some examples, the paymentprocessor 510 uses an HTTP-based tokenization API in steps (2) and (4)above. Some broader examples may be considered as “tokenization as aservice,” in which any data is tokenized. One general example mayfacilitate a merger and acquisition (M&A) analysis in which companieswant to compare an overlap in their customer bases. A payment processor510 (acting as a tokenization service) can tokenize the customers 504 ofeach company and compare the overlap without revealing confidentialinformation to either party. Unique payment tokens can be adapted toenable and facilitate such a tokenization service.

Before accepting payment online with the payment processor 510, aninventory API 612 can check for availability of the ordered product aswell as allow for preorders and backorders. The ordered product may bephysical (e.g., a pin) and/or virtual, such as software, non-fungibletokens (NFT), etc. Preorders and backorders are both similar in thatthey allow selling of stock that cannot yet be shipped, and also verydifferent in that sellers use them for different strategies which getreflected in various user interfaces, e.g. preorders to build hypeleading up to a new product launch, and backorders to continue sellingto customers going to a competitor.

When a product goes out of stock, a merchant may want to do one of threethings: stop selling the product; sell an unlimited number ofbackorders; sell a finite number of backorders. For a preorder, amerchant may want to: sell an unlimited number of preorders or sell afinite number of preorders.

The inventory API 612 has two quantity tracking fields:—‘orderable,’which defines how many times this item can be sold (regardless of if itis physically in stock or not), and may be infinite; and ‘in-stock,’which defines how many items are stocked and ready to be fulfilled. Bothof these fields can be atomically incremented using a‘/v1/inventories/:id/adjust’ endpoint. The inventory API 612 also workswith an Order API 610, where new Orders automatically decrement from theinventory API 612. Each inventory adjustment is also tracked in a‘InventoryTransaction’ object, which serves as a historical audit trailof the movement of inventory. By setting orderable to a value greaterthan in_stock, merchants can use the inventory API 612 to sell either apreorder or a backorder.

An example of a merchant selling pins using the inventory API 612 willnow be provided. Cindy's Llama Pins is a new e-commerce startup usingthe payment processor 510. Cindy sells a variety of pins and manages thefulfillment (i.e., packing, shipping) herself. Cindy has already createdProducts and Product Classes to represent the pins being sold. She nowcreates Inventory objects and updates the Products to have Inventory.The Blue Llama Pin product has 100 units in stock.

 1 POST /v1/ inventories  2 {  3  orderable : 100 ,  4  in_stock : 100 , 5 }  6 => {  7  id: ‘inv_567’ ,  8  object: ‘inventory’ ,  9  livemode:true , 10  created: 1610600000 , 11  updated: 1610600000 , 12  metadata:{ }, 13   14  orderable : 100 , 15  in_stock : 100 , 16 } 17 18 POST/v1/products/blue_llama_pin 19 { 20  inventory: ‘inv_123’ , 21 } 22 => {23  id: ‘blue_llama_pin’ , 24  inventory: ‘inv_123’ , 25  ... 26 }

Rendering a Product Detail Page

Now that Inventory is fully set up, Cindy wants to render stock statuson a product detail pages for her webstore. An example code snippet inRuby:

 1 DISPLAY_LOW_STOCK_THRESHOLD = 20  2  3 def get_inventory_status(product_id)  4 inventory = Stripe::Product.retrieve({  5 id:product_id,  6 expand: [ ‘inventory’ ],  7 }).inventory  8 ifinventory.in_stock == 0  9 ‘Out of Stock’ 10 elsif inventory.in_stock <DISPLAY_LOW_STOCK_THRESHOLD 11 ‘Low Stock’ 12 else 13 ‘In Stock’ 14 end15 end

Sell Product Using Orders

When the Blue Llama Pin is sold in an Order, both orderable and in_stockon the associated Inventory object are decremented. The Order will showthat the corresponding line item is currently in_stock. A low stockalert can be triggered per this code snippet.

1 REORDER_LOW_STOCK_THRESHOLD = 15 2 3 def handle_low_stock (inventory_from_webhook ) 4 return if inventory_from_webhook.in_stock >REORDER_(—) LOW_STOCK_THRESHOLD 5reorder_from_manufacturer(inventory_from_webhook.id) 6 end

When this threshold is breached, she filters Products by inventories tosee which Products she needs to order more stock for.

1 GET /v1/products ? inventories [ ]= ‘inv_123’ 2 => { 3 object: ‘list’, 4 ... 5 }

The Blue Llama Pin product is popular and ends up selling out. Ordersfor Blue Llama Pins are now blocked.

1 { 2 id : ‘inv_123’ , 3 orderable : 0 , 4 in_stock : 0 , 5 ... 6 }

Restock Inventory

A shipment of 200 pins came in and Cindy can now restock Blue Llama Pin.

 1 POST /v1/inventories/inv_123/restock  2 {  3 quantity: 200 ,  4 }  5=> {  6 id: ‘inv_123’ ,  7 orderable : 200 ,  8 in_stock : 200 ,  9 ...10 }

Cindy has also set up a “Notify me when back in stock” email signup liston a product detail page. To trigger these emails, she listens to theinventory.quantity.updated webhook. Each time it fires with non-zeroquantities, the inventory API 612 or other entity sends out thoseemails, and can clear out those signups.

1 def notify_back_in_stock ( inventory_from_webhook ) 2 return ifinventory_from_webhook.in_stock == 0 3 4 emails_to_notify =retrieve_emails_list(inventory_from_webhook.id) 5 6 if(emails_to_notify.length > 0 ) 7 notify(emails_to_notify,inventory_from_webhook.id) 8  end 9 end

Selling Preorders Fulfilled by Third Party Logistics (3PL)

Cindy can no longer pack and ship all her orders herself, so she decidesto make use of a third party logistics (3PL) company to handle all ofher order fulfillment. Cindy also decides to experiment with sellingpreorders, and decides on an AlpacaPin as her first preorder-ableproduct. To generate hype for this new product, she decides to onlyaccept 50 preorders. She is reasonably confident that people likealpacas, and places an order of 200 Alpaca Pins with her manufacturer,which will be delivered to the 3PL in a month (at time 1620600000).

Create Inventory in preorder mode  1 POST /v1/inventories  2 => {  3orderable: 50 ,  4 in_stock : 0 ,  5 }  6 => {  7 id: ‘inv_567’ ,  8object: ‘inventory’ ,  9 livemode: true , 10 created: 1610600000 , 11updated: 1610600000 , 12 metadata: { }, 13 14 orderable: 50 , 15in_stock: 0 , 16 }

Selling Preorders

When the Alpaca Pin is sold by an Order, the Order decrements orderableon the Inventory corresponding to that line item's product. Becausein_stock is zero, the Order tracks that this line item is currently notin_stock.

1 POST /v1/orders/order_5/submit { ... } 2 => { ... } 3 4 // Inventory 5{ 6 orderable: 49 , 7 in_stock: 0 , 8 ... 9 }

Each Order that is generated is mirrored into the 3PL's Orders API. TheAlpaca Pins are a hit, and sell out in two days! At this point, newOrders containing any Products referencing this Inventory will beblocked.

1 { 2 orderable : 0 , 3 in_stock : 0 , 4 ... 5 }

Increase preorder-able quantity Cindy does not want buzz for her AlpacaPins to die down and decides to release some 50 more units for preorder.

1 POST /v1/inventories/inv_567/adjust 2 { 3 adjust_orderable_quantity:50 , 4 } 5 => { 6 orderable: 50 , 7 in_stock: 0 , 8 ... 9 }Transition from Preorder to in Stock

A month later, the 200 pins finally arrive at the 3PL. Cindy confirmsthat it has been received by polling a Warehouse Receiving Order API tosee that it has arrived and successfully stocked. She then restocks theinventory API 612.

 1 // Initial Inventory state  2 {  3 orderable: 0 ,  4 in_stock: 0 ,  5...  6 }  7  8 POST /v1/inventories/inv_567/restock  9 { 10  quantity:200 , 11 } 12 => { 13 orderable: 200 , 14 in_stock: 200 , 15 ... 16 }

The 3PL sends an order_shipped webhook for each Order it fulfills and aFulfillment API updates each order's fulfillment status. Doing socreates a Fulfillment, and decrements from the Inventory's in_stocksince the in_stock_quantity on the line item was 0.

Accepting Backorders/Increasing Backorder Limits

Cindy's manufacturer tells her that they are confident in their abilityto produce more Alpaca Pins. In order to avoid losing customers to hercompetitor, Cindy decides to start accepting backorders—i.e., continueselling her Alpaca Pins even after they sell out at her 3PL warehouse.Just in case anything goes wrong at her manufacturer's factory, shedecides to limit herself to selling up to 100 backorders at a time.

1 POST /v1/inventories/inv_567/adjust 2 { 3 adjust_orderable_quantity:100 4 } 5 => { 6 orderable: 200 , 7 in_stock: 100 , 8 ... 9 }

If Cindy wanted to further increase the number of backorders she canaccept, she would use the same/adjust operation as the above.

Reorder Inventory

When an inventory.quantity.updated triggers with a in_stock quantitybelow her internally configured threshold, Cindy places a new bulk orderfor 100 units with her manufacturer. Her manufacturer also unfortunatelynotifies her that they will be retooling their dies after this order,and that they will no longer be able to produce Alpaca Pins.

Selling Backorders

Similar to preorders, the Order tracks each line item that cannot beimmediately fulfilled. Cindy decides to allow Orders where a singleProduct has some mix of in_stock and backordered units—before they pay,she notifies her customer that the entire Order will ship once thebackordered units arrive. She could just as easily disallow purchasingOrders that have a mix of backordered and in_stock units, and requirethe customer to reduce their quantity.

 1 // Initial Inventory state  2 {  3 orderable: 105 ,  4 in_stock: 5 , 5 ...  6 }  7  8 POST /v1/orders/ order_123 /submit { ... }  9 => { 10line_items: [{ 11 quantity: 10 12 }] 13 . . . 14 } 15 16 // FinalInventory state 17 { 18 orderable: 95 , 19 in_stock: 0 , 20 ... 21Transition from Backorder to in Stock

The new shipment of 100 Alpaca Pins arrives at the 3PL before any morepins are sold. Cindy once again polls the 3PL's Inventory API todetermine how many units are in_stock and sees that there are 100total_onhand_quantity. As before, the 3PL fulfills the backordered orderand notifies Cindy via webhook. Because her manufacturer can no longerproduce these pins, she uses the/adjust endpoint instead of/restock whenreflecting this in the payment processor 510.

1 POST /v1/inventories/inv_567/ adjust 2 { 3 in_stock: 100 , adjust _(—)4 } 5 => { 6 orderable: 100 , 7 in_stock: 100 , 8 ... 9 }

Now that the Alpaca Pins are back in stock, Cindy can fulfill heroutstanding Order, order_123, by calling a fulfillment API, which willdecrement from in_stock.

User Flow: Selling Products Fulfilled by a Print onDemand Service

One problem with Cindy's business model is that some pins sell quicklyand go out of stock while other pins are always in stock. She decides tochange her strategy and finds a new Print On Demand partner (API), thatuses a blank pin to back many different Products.

Many to One Setup

This is modeled by one Inventory object that is shared across multipleProducts.

Cindy creates a new Inventory object, and updates her existing Productsto point to this new Inventory

 1 POST /v1/inventories  2 {  3 orderable : 300 ,  4 in_stock : 300 ,  5}  6 => {  7 id: ‘inv_456’ ,  8 orderable : 300 ,  9 in_stock : 300 , 10... 11 } 12 13 POST /v1/products/blue_llama_pin 14 { 15 inventory:‘inv_456’ , 16 } 17 => ... 18 19 POST /v1/products/red_llama_pin 20 { 21inventory: ‘inv_456’ , 22 } 23 => ... 24 25 POST/v1/products/green_llama_pin 26 { 27 inventory: ‘inv_456’ , 28 } 29 =>...

Write Off Inventory Loss

Cindy notices that 50 blank pins have a dent in them and cannot be sold.She corrects for this through the Adjust API.

 1 POST /v1/inventories/inv_456/adjust  2 {  3 adjust_ orderable : −50 , 4 adjust_in_stock : −50 ,  5 }  6 => {  7 id: ‘inv_456’ ,  8 orderable: 250 ,  9 in_stock : 250 , 10 ... 11 }

FIG. 6 is a block diagram showing aspects of an inventory systemaccording to an example embodiment. The inventory system 600 comprisesInventory Related Databases (DBs) 618, (which comprises an Inventory DB602 and an inventory transaction DB 616) and Application ProgramInterfaces APIs 608. The Inventory DB 602 comprises at least two fieldsincluding Orderable 604 and In-stock 606. The APIs 608 comprises orderAPI 610 and an inventory API 612, and DB Lock 614. The Inventory DB 602will have the following: A DB Lock 614; Orderable 604 and an In-stock606 which respectively indicate how many units of a product areavailable for purchase and how many units the merchant has on hand thatare uncommitted to the order API 610; a metadata hash also allowingusers to specify additional information on Inventory DB 602; and createdtimestamp fields. By setting Orderable 604 to a value greater thanIn-stock 606, merchants can use the inventory API 612 to sell either apreorder or a backorder.

The inventory API 612 has the ability to block Orders from the order API610. When an Order is submitted with a Product that is using theinventory API 612, the order API 610 will attempt to decrement theOrderables 604 and In-stock 606 by the quantity on the line item of anorder. If Orderable 604 would go negative, then the Order is blocked,otherwise the Order goes through. If In-stock 606 would staynon-negative, meaning the product is in stock, then the Order line itemwill show that is currently in stock. Otherwise, in the case orpreorders or backorders, the line item will show that it is awaitingstock.

The DB Lock 614 will lock the Inventory DB 602 so that the inventory API612 cannot decrement the Orderable 604 or In-stock 606. Locking can beuseful when restocking inventory to prevent a race condition with theInventory DB 602. For example, when a merchant is incrementing theIn-stock 606 and/or the Orderable 604 an order may come in via the orderAPI 610 causing the inventory API 612 to decrement the In-stock 606 andOrderable 604 simultaneously with the incrementing. By locking theInventory DB 602 against changes by the inventory API 612, the InventoryDB 602 can be updated properly and orders can then be processedcorrectly by the order API 610. The APIs 608 will be discussed in moredetail in conjunction with FIG. 7 .

Note that while the Orderable 604 and In-stock 606 are shown in adatabase, other locations are possible for these fields. Similarly,other locations are available for the fields in the inventorytransactions database 616.

Each time the Inventory DB 602 values are changed (after acquiring theDB lock), the system 600 generates an InventoryTransaction record storedin the Inventory Transaction DB 616, which captures the details of thatchange for record keeping and use for auditing. The InventoryTransaction DB 616 comprises order-adjusted 620, resulting_orderable622, in_stock_adjusted 624, resulting_in_stock 626, transaction number628, and previous transaction 630. The fields in the inventorytransaction database 616 are explained as follows:

orderable_adjusted 620—the orderable quantity that was adjusted by thistransaction, i.e. the delta value between the orderable quantity beforeadjustment, and the orderable quantity after adjustment.

in_stock_adjusted 624—the in_stock quantity that was adjusted by thistransaction, i.e. the delta value between the in_stock quantity beforeadjustment, and the in_stock quantity after adjustment.

resulting_orderable 622—the orderable quantity after the adjustment madeby this transaction

resulting_in_stock 626—the in_stock quantity after the adjustment madeby this transaction

transaction_number 628—a monotonically increasing unique identifiernumber for this transaction

previous_inventory_transaction 630—a reference to the previoustransaction for this inventory

FIG. 7 illustrates a method 700 of preventing race conditions in aninventory database. In block 702, a merchant sets Orderable 604 andIn-stock 606 in the Inventory DB 602 or other location via, for example,a graphical user interface. In block 704, the order API 610 receives anorder for a product related to the Orderable 604 and In-stock 606. Indecision block 706, the order API 610 determines if the Inventory DB 602is locked by the DB Lock 614. In block 708, if the Inventory DB 602 islocked, then, at block 708, the system 600 waits to acquire lock for thereceived order and then proceeds to decision 710. The locking is toprevent a race condition in the Inventory DB 602 so that data in theInventory DB 602 isn't simultaneously receiving decrements andincrements. During the lock, the order is suspended but can be processedonce the lock is released. That is, the lock doesn't necessarily rejectparallel transactions, but forces a particular order to thosetransactions so an operation can happen atomically. This means that thefirst online transaction may be delayed and wait until the lock is nolonger held, rather than being immediately rejected.

In decision block 710, if the Inventory DB 602 was not locked (or is nowunlocked) or the Inventory DB 602 has been updated and then unlocked,the inventory API 612 determines if the product is orderable. That is,is there enough inventory to fulfil the order (e.g., if the Orderable604 would go negative if the order was completed). If Orderable 604indicates insufficient product, then in block 712, the order API 610rejects the order. Note that the Orderable 604 can be set to unlimitedso that it will never go negative. If the Orderable 604 would not gonegative, then in block 714, the inventory API 612 decrements orderableby a number specified in the order.

Next, in decision block 716, the inventory API 612 determines if theproduct is in-stock as indicated by the In-stock 606 being greater thanzero (or would not go negative if the order was fulfilled). If notin-stock (e.g., because backordered or preordered), then in block 718,the system 600 awaits a shipment and increments in-stock when a shipmentarrives and the order can process at block 720. In block 720, theinventory API 612 decrements In-stock 606 (at the same amount that theOrderable 604 is decremented) and the order is processed (e.g., shipped,online network or database access provided, etc.) in block 722.

In an example, the method 700 can further comprise generating ahistorical audit trail of inventory movement based on the decrementingthe In-stock 606 (e.g., by keeping a record of each time In-stock 606has been changed). In another example, the method 700 further comprisestransmitting an electronic communication to at least one customerinforming the at least one customer of the update in block 708 (e.g.,when Orderable 604 is increased so that a rejected order can now becompleted).

Further, each time the Inventory DB 602 values are changed (e.g., afteracquiring the DB lock or decrementing at blocks 714 and or 720), thesystem 600 can generate a InventoryTransaction or online transactionrecord, which captures the details of that change for record keeping anduse for auditing. That record can be stored in the inventory (online)transaction database 616 as described above.

Note that while the method 700 has been described in relation to anonline order, it can be applied to any online transaction, such asaccessing a computer network, accessing a computer database, accessingan online subscription service, etc. where access may be limited to acertain number of users (e.g., to prevent slowing the network down).

Accordingly, the method 700 prevents race conditions, such assimultaneous decrementing and incrementing data in the Inventory DB 602,which would otherwise potentially corrupt data in the Inventory DB 602.

In view of the disclosure above, various examples are set forth below.It should be noted that one or more features of an example, taken inisolation or combination, should be considered within the disclosure ofthis application.

1. A method for preventing race conditions in a database by at least onehardware processor, comprising:

setting a first numerical entry and a second numerical entry in adatabase;receiving a first online transaction;responsive to determining a lock of the database is in progress due to asecond received online transaction, suspending the first onlinetransaction;removing the lock after the second received online transaction iscompleted;responsive to determining that the first entry is greater than zero,decrementing the first entry by an amount indicated in the first onlinetransaction;responsive to determining the second entry is greater than zero,decrementing the second entry; processing the first transaction; andgenerating an online transaction record for the first transaction andstoring the generated record in an online transaction database.

2. The method of example 1, further comprising decrementing the secondentry in a same amount that the first entry was decremented.

3. The method of any of the preceding examples, wherein the first entryis always equal to or greater than the second entry.

4. The method of any of the preceding examples, wherein the first entryrepresents a back-order quantity.

5. The method of any of the preceding examples, wherein the first entryrepresents a preorder quantity.

6. The method of any of the preceding examples, wherein the first entryis set to unlimited.

7. The method of any of the preceding examples, further comprisingbefore the removing the lock, updating the second entry.

8. The method of any of the preceding examples, wherein the onlinetransaction record comprises numerical values including order-adjusted,resulting_orderable, in_stock_adjusted, and resulting_in_stock.

9. The method of any of the preceding examples, further comprising inresponse to determining the first entry would turn negative if the firstonline transaction was accepted, rejecting the first online transaction.

10. A non-transitory computer-readable storage medium, thecomputer-readable storage medium including instructions that whenexecuted by a computer, cause the computer to perform operationscomprising:

setting an orderable entry and an in-stock entry in a database;receiving a first online transaction;responsive to determining a lock of the database is in progress due to asecond received online transaction, suspending the first onlinetransaction;removing the lock after the second received online transaction iscompleted;responsive to determining that the first orderable is greater than zero,decrementing the orderable entry by an amount indicated in the firstonline transaction;responsive to determining the second entry is greater than zero,decrementing the in-stock entry;processing the first transaction; andgenerating an online transaction record for the first transaction andstoring the generated record in an online transaction database.

11. A database system, comprising:

one or more hardware processors; anda memory storing instructions that, when executed by at least oneprocessor among the processors, cause the system to perform operationscomprising, at least:setting an orderable entry and an in-stock entry in a database;receiving a first online transaction;responsive to determining a lock of the database is in progress due to asecond received online transaction, suspending the first onlinetransaction;removing the lock after the second received online transaction iscompleted;responsive to determining that the first orderable is greater than zero,decrementing the orderable entry by an amount indicated in the firstonline transaction;responsive to determining the second entry is greater than zero,decrementing the in-stock entry; processing the first transaction; andgenerating an online transaction record for the first transaction andstoring the generated record in an online transaction database.

12. The database system of any of the preceding examples, wherein theoperations further comprise decrementing the in-stock entry in a sameamount that the order entry was decremented.

13. The database system of any of the preceding examples, wherein theorderable entry is greater than the in-stock entry.

14. The database system of any of the preceding examples, wherein theorderable entry represents a back order quantity.

15. The database system of any of the preceding examples, wherein theorderable entry represents a preorder quantity.

16. The database system of any of the preceding examples, wherein theorderable entry is set to unlimited.

17. The database system of any of the preceding examples, wherein theoperations further comprise generating a historical audit trail ofinventory movement based on the decrementing the in-stock entry.

18. The database system of any of the preceding examples, wherein theoperations further comprise before the removing the lock, updating thein-stock entry.

19. The database system of any of the preceding examples, wherein theoperations further comprise in response to determining the orderableentry would turn negative if the second online order was accepted,rejecting the second online order and removing the lock.

20. The database system of any of the preceding examples, wherein theonline transaction record comprises numerical values includingorder-adjusted, resulting_orderable, in_stock_adjusted, andresulting_in_stock.

It should also be noted that the above operations and techniques aredescribed as being performed by the payment processor 510 or the APIs608; however, some or all of the operations may be performed by adifferent entity, such as by the merchant 502 itself (using, forexample, a JavaScript library of functions provided by the paymentprocessor 510).

Some embodiments include machine-readable media including instructions410 which, when read by a machine 400, cause the machine 400 to performthe operations of any one or more of the methodologies summarized above,or described elsewhere herein.

Although the subject matter has been described with reference tospecific example embodiments, it will be evident that variousmodifications and changes may be made to these embodiments withoutdeparting from the broader scope of the disclosed subject matter.Accordingly, the specification and drawings are to be regarded in anillustrative rather than a restrictive sense. The accompanying drawingsthat form a part hereof show by way of illustration, and not oflimitation, specific embodiments in which the subject matter may bepracticed. The embodiments illustrated are described in sufficientdetail to enable those skilled in the art to practice the teachingsdisclosed herein. Other embodiments may be utilized and derivedtherefrom, such that structural and logical substitutions and changesmay be made without departing from the scope of this disclosure. ThisDescription, therefore, is not to be taken in a limiting sense, and thescope of various embodiments is defined only by any appended claims,along with the full range of equivalents to which such claims areentitled.

Such embodiments of the inventive subject matter may be referred toherein, individually and/or collectively, by the term “invention” merelyfor convenience and without intending to voluntarily limit the scope ofthis application to any single invention or inventive concept if morethan one is in fact disclosed. Thus, although specific embodiments havebeen illustrated and described herein, it should be appreciated that anyarrangement calculated to achieve the same purpose may be substitutedfor the specific embodiments shown. This disclosure is intended to coverany and all adaptations or variations of various embodiments.Combinations of the above embodiments, and other embodiments notspecifically described herein, will be apparent to those of skill in theart upon reviewing the above description.

What is claimed is:
 1. A method for preventing race conditions in adatabase by at least one hardware processor, comprising: setting a firstnumerical entry and a second numerical entry in a database; receiving afirst online transaction; responsive to determining a lock of thedatabase is in progress due to a second received online transaction,suspending the first online transaction; removing the lock after thesecond received online transaction is completed; responsive todetermining that the first entry is greater than zero, decrementing thefirst entry by an amount indicated in the first online transaction;responsive to determining the second entry is greater than zero,decrementing the second entry; processing the first transaction; andgenerating an online transaction record for the first transaction andstoring the generated record in an online transaction database.
 2. Themethod of claim 1, further comprising decrementing the second entry in asame amount that the first entry was decremented.
 3. The method of claim1, wherein the first entry is always equal to or greater than the secondentry.
 4. The method of claim 1, wherein the first entry represents aback-order quantity.
 5. The method of claim 1, wherein the first entryrepresents a preorder quantity.
 6. The method of claim 1, wherein thefirst entry is set to unlimited.
 7. The method of claim 1, furthercomprising before the removing the lock, updating the second entry. 8.The method of claim 1, wherein the online transaction record comprisesnumerical values including order-adjusted, resulting_orderable,in_stock_adjusted, and resulting_in_stock.
 9. The method of claim 1,further comprising in response to determining the first entry would turnnegative if the first online transaction was accepted, rejecting thefirst online transaction.
 10. A non-transitory computer-readable storagemedium, the computer-readable storage medium including instructions thatwhen executed by a computer, cause the computer to perform operationscomprising: setting an orderable entry and an in-stock entry in adatabase; receiving a first online transaction; responsive todetermining a lock of the database is in progress due to a secondreceived online transaction, suspending the first online transaction;removing the lock after the second received online transaction iscompleted; responsive to determining that the first orderable is greaterthan zero, decrementing the orderable entry by an amount indicated inthe first online transaction; responsive to determining the second entryis greater than zero, decrementing the in-stock entry; processing thefirst transaction; and generating an online transaction record for thefirst transaction and storing the generated record in an onlinetransaction database.
 11. A database system, comprising: one or morehardware processors; and a memory storing instructions that, whenexecuted by at least one processor among the processors, cause thesystem to perform operations comprising, at least: setting an orderableentry and an in-stock entry in a database; receiving a first onlinetransaction; responsive to determining a lock of the database is inprogress due to a second received online transaction, suspending thefirst online transaction; removing the lock after the second receivedonline transaction is completed; responsive to determining that thefirst orderable is greater than zero, decrementing the orderable entryby an amount indicated in the first online transaction; responsive todetermining the second entry is greater than zero, decrementing thein-stock entry; processing the first transaction; and generating anonline transaction record for the first transaction and storing thegenerated record in an online transaction database.
 12. The databasesystem of claim 11, wherein the operations further comprise decrementingthe in-stock entry in a same amount that the order entry wasdecremented.
 13. The database system of claim 11, wherein the orderableentry is greater than the in-stock entry.
 14. The database system ofclaim 11, wherein the orderable entry represents a back order quantity.15. The database system of claim 11, wherein the orderable entryrepresents a preorder quantity.
 16. The database system of claim 11,wherein the orderable entry is set to unlimited.
 17. The database systemof claim 11, wherein the operations further comprise generating ahistorical audit trail of inventory movement based on the decrementingthe in-stock entry.
 18. The database system of claim 11, wherein theoperations further comprise before the removing the lock, updating thein-stock entry.
 19. The database system of claim 11, wherein theoperations further comprise in response to determining the orderableentry would turn negative if the second online order was accepted,rejecting the second online order and removing the lock.
 20. Thedatabase system of claim 11, wherein the online transaction recordcomprises numerical values including order-adjusted,resulting_orderable, in_stock_adjusted, and resulting_in_stock.